﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ICart>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <%: Html.Partial("Sidebar") %>
    <div id="main">
        <div class="main-block">
            <h2 class="title">
                <%:"Checkout".Localize() %></h2>
            <div class="main-block-content cart-content clearfix">
                <%: Html.Partial("Progress",2)%>
                <h6>
                    <%:"Shipping Address".Localize() %></h6>
                <%using (Html.BeginForm("shipping", "cart"))
                  { %>
                <div class="cart-block">
                    <% var addresses = ViewState["addresses"] as List<IAddress>;

                       if (addresses != null && addresses.Count > 0)
                       { %>
                    <table>
                        <tbody>
                            <% foreach (var i in addresses)
                               {  %>
                            <tr>
                                <td>
                                    <input type="radio" value="<%: i.Id %>" name="address" />
                                </td>
                                <td>
                                    <%: i.FirstName %><%: i.LastName %>
                                </td>
                                <td>
                                    <%: i.City %>
                                    <%: i.State %>
                                    <%: i.CountryName %>
                                </td>
                                <td>
                                    <%: i.Address1 %>
                                    <%: i.Address2 %>
                                </td>
                                <td>
                                    <%: i.Postcode %>
                                </td>
                                <td>
                                    <%: i.Phone %>
                         
                                    <script type="text/javascript">
                                        set("<%: i.FirstName  %>", "<%: i.LastName %>",  "<%: i.Phone  %>", "<%: i.Address1 %>", "<%: i.Address2  %>", "<%: i.City %>", "<%: i.Postcode %>", "<%: i.CountryCode %>", "<%: i.State %>")
                                    </script>
                                </td>
                            </tr>
                            <%} %>
                        </tbody>
                    </table>
                    <script type="text/javascript">
                        function set(firstName, lastName,  phone, address1, address2, city, postcode, countrycode, state) {
                            $("#FirstName").val(firstName);
                            $("#LastName").val(lastName);
                   
                            $("#Phone").val(phone);
                            $("#Address1").val(address1);
                            $("#Address2").val(address2);
                            $("#City").val(city);
                            $("#Postcode").val(postcode);
                            $("#CountryCode").val(countrycode);
                            $("#State").val(state);
                        }
                    </script>
                    <%} %>
                    <div class="common-form">
                        <fieldset>
                            <p>
                                <label for="FirstName">
                                    <span>*</span>
                                    <%: "FirstName".Localize() %>
                                </label>
                                <%: Html.TextBoxFor(i=>i.FirstName) %>
                                <%: Html.ValidationMessageFor(i=>i.FirstName) %>
                            </p>
                            <p>
                                <label for="LastName">
                                    <span>*</span>
                                    <%: "LastName".Localize() %>
                                </label>
                                <%: Html.TextBoxFor(i=>i.LastName) %>
                                <%: Html.ValidationMessageFor(i=>i.LastName) %>
                            </p>
                
                            <p>
                                <label for="Phone">
                                    <span>*</span>
                                    <%: "Phone".Localize() %>
                                </label>
                                <%: Html.TextBoxFor(i=>i.Phone) %>
                                <%: Html.ValidationMessageFor(i=>i.Phone) %>
                            </p>
                            <p>
                                <%: Html.LabelFor(i=>i.Address1) %>
                                <%: Html.TextBoxFor(i=>i.Address1) %>
                                <%: Html.ValidationMessageFor(i=>i.Address1) %>
                            </p>
                            <p>
                                <%: Html.LabelFor(i=>i.Address2) %>
                                <%: Html.TextBoxFor(i=>i.Address2) %>
                                <%: Html.ValidationMessageFor(i=>i.Address2) %>
                            </p>
                            <p>
                                <label for="City">
                                    <span>*</span>
                                    <%: "City".Localize() %>
                                </label>
                                <%: Html.TextBoxFor(i => i.City)%>
                                <%: Html.ValidationMessageFor(i => i.City)%>
                            </p>
                            <p>
                                <label for="Postcode">
                                    <span>*</span>
                                    <%: "Postcode".Localize() %>
                                </label>
                                <%: Html.TextBoxFor(i => i.Postcode)%>
                                <%: Html.ValidationMessageFor(i => i.Postcode)%>
                            </p>
                            <p>
                                <label for="country">
                                    <span>*</span> Country</label>
                                <%: Html.SelectorFor("Country.CountryCode",this.Model.Country,false) %>
                            </p>
                            <p>
                                <%: Html.LabelFor(i=>i.State) %>
                                <%: Html.TextBoxFor(i=>i.State) %>
                                <%: Html.ValidationMessageFor(i=>i.State) %>
                            </p>
                        </fieldset>
                    </div>
                </div>
                <h6>
                    Shipping Method</h6>
                <div class="cart-block">
                    <p>
                        Please select the preferred shipping method to use on this order.</p>
                    <table>
                        <tbody>
                            <% foreach (var item in AppContext.EntityFactory.Shippings.Where(i => i.IsEnable))
                               {
                            %>
                            <tr>
                                <td>
                                    <%: item.HeadLine %>
                                </td>
                                <td>
                                    <table>
                                        <% foreach (var option in item.Options.Where(i => i.IsEnable))
                                           {
                                     

                                               var isselected = item.Name == this.Model.ShippingName && option.Name == this.Model.ShippingOptionName;
                                        %>
                                        <tr>
                                            <td>
                                                <input type="radio" value="<%: option.Name %>" name="ShippingOptionName" <%: isselected? "checked='checked'":"" %> onclick="selectShipping('<%= item.Name %>')" />
                                            </td>
                                            <td>
                                                <strong>
                                                    <%: option.HeadLine %>
                                                    (
                                                    <%: option.Rate(this.Model).ToString("c") %>)</strong>
                                                <p>
                                                    <%: item.HeadLine %>
                                                </p>
                                            </td>
                                        </tr>
                                        <%
                                            } 
                                        %>
                                    </table>
                                </td>
                            </tr>
                            <% 
                               } 
                            %>          
                        </tbody>
                    </table>
                </div>

                <h6>InsuredAmount </h6>
                <div class=cart-block>
                    <%: Html.LabelFor(i=>i.InsuredAmount) %>
                    <%: Html.TextBoxFor(i=>i.InsuredAmount) %>
                </div>

                <div class="buttons">
                    <a href="/cart" class="button left"><span>« Back</span></a>
                    <button type="submit" class="button right">
                        <em><span>Next »</span></em></button>
                </div>
                <%: Html.HiddenFor(i=>i.ShippingName) %>
<script type="text/javascript">
    function selectShipping(name) {
        $("input[name=ShippingName]").val(name);
    }
</script>
      <%} %>
            </div>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="JSContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Breadcrumb" runat="server">
    <ul class="breadcrumb">
        <li><a href="/Home/Index">Home</a>&gt;</li>
        <li>Cart</li>
    </ul>
</asp:Content>
